import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class Email_Pin
{   
   static  String SMTP_AUTH_USER = "sanchitgarg6";
   static  String SMTP_AUTH_PWD  = "1234abcd";
  
  public  void sendmail(String rec_name, String rec_email, String pin) throws Exception
  {
     boolean debug = false;
     Properties props = new Properties();
     props.put("mail.smtp.host", "smtp.gmail.com");
     props.put("mail.smtp.auth", "true");
     props.put("mail.smtp.starttls.enable", "true");

    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);

    session.setDebug(debug);

    Message msg = new MimeMessage(session);

    InternetAddress addressFrom = new InternetAddress("sanchitgarg6@gmail.com");
    msg.setFrom(addressFrom);

    InternetAddress rec_add = new InternetAddress();
    
    rec_add = new InternetAddress(rec_email);
    
    msg.setRecipient(Message.RecipientType.TO, rec_add);

    String message=" Dear "+rec_name+"\n Thank you for registering! Please find your bin below";
    message=message+"\n\n Pin: "+pin;
    message=message+"\n\n Please use this pin while accessing IVRS from your registered mobile number.";
    message=message+"\n\n\n Regards \n Development Team";

    msg.setSubject("Pin for accessing Course assessment details on IVRS");
    msg.setContent(message, "text/plain");
    Transport.send(msg);
 }
      
 
private class SMTPAuthenticator extends javax.mail.Authenticator
{

    public PasswordAuthentication getPasswordAuthentication()
    {
        String username = SMTP_AUTH_USER;
        String password = SMTP_AUTH_PWD;
        return new PasswordAuthentication(username, password);
    }
}

}


